## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## 
## Attaching package: 'plotly'
## 
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## 
## The following object is masked from 'package:graphics':
## 
##     layout

Column

Boxplot

To create a bax plot showing the distribution of people’s order hour for each aisle

data("instacart")
box = instacart|>
  group_by(aisle,order_hour_of_day)|>
  mutate(n_order=n())|>
  filter(n_order>1000)

plot_ly(box,x = ~aisle, y = ~order_hour_of_day,color=~aisle, type = "box",colors="viridis")

Column

Barplot

To make a bar plot to visualize the number of popular products in each aisles

day = instacart|>
  group_by(aisle)|>
  summarize(n_products=n())|>
  filter(n_products>10000)|>
  mutate(aisle=fct_reorder(aisle,n_products))

plot_ly(day, x=~aisle,y=~n_products,color=~aisle,type="bar",colors="viridis")

Lineplot

summary = instacart |> 
  group_by(order_hour_of_day) |> 
  summarize(
    average_days_since_prior = mean(days_since_prior_order, na.rm = TRUE))

plot_ly(data = summary,
        x = ~order_hour_of_day,
        y = ~average_days_since_prior,
        type = "scatter",
        mode = "lines+markers") |> 
  layout(title = "Average Days Since Prior Order by Order Hour of the Day",
         xaxis = list(title = "Order Hour of Day"),
         yaxis = list(title = "Average Days Since Prior Order"))